#!/usr/bin/python
#coding:utf-8
'''
线程池模型
'''

from concurrent.futures import ThreadPoolExecutor #线程池用库

pool = ThreadPoolExecutor(10)

def task(url):
    return url

def done(future,*args,**kwargs):
    response = future.result()   #取得future对象进行操作
    print(response.status_code,response.content)

url_list = (
    "https://www.bing.com",
    "https://www.jd.com",
    "https://www.sina.com",
    "https://www.baidu.com",
    "https://www.cnblogs.com",
    "https://music.163.com/#"
)

for url in url_list:
    v = pool.submit(task,url)    #获得一个返回值,其实就是访问url的响应
    # v.add_done_callback(done) #结果执行另一个方法
    print(v.result())
    